• Projects
  • R Packages
  • Publications
  • Graduate Students
  • Links
  • Courses
    • Single-case regression analzes
  • Private blog

On this page

  • Hi Wolfgang and Michel, here is a simple example to show the differences between treatment and effect contrast.
  • Example dataset
  • Descriptives
  • Contrasts

What’s that all about the contrasts

methods
stats
contrasts
Author

Jürgen Wilbert

Published

May 17, 2023

Hi Wolfgang and Michel, here is a simple example to show the differences between treatment and effect contrast.

Example dataset

Create a random dataset with criteria y, predictors x1 and x2 and gender.

All variables are correlated.

n <- 10000
gender <- rep(0:1, each = n/2)
y <- sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)
x1 <- y + sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)
x2 <- y + x1 + sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)

dat <- data.frame(y = y, x1 = x1, x2 = x2, gender = gender)

Descriptives

psych::corr.test(dat)
Call:psych::corr.test(x = dat)
Correlation matrix 
          y   x1   x2 gender
y      1.00 0.80 0.86   0.54
x1     0.80 1.00 0.93   0.67
x2     0.86 0.93 1.00   0.73
gender 0.54 0.67 0.73   1.00
Sample Size 
[1] 10000
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
       y x1 x2 gender
y      0  0  0      0
x1     0  0  0      0
x2     0  0  0      0
gender 0  0  0      0

 To see confidence intervals of the correlations, print with the short=FALSE option
psych::describe(dat)
vars n mean sd median trimmed mad min max range skew kurtosis se
y 1 10000 7.4457 4.589897 7.0 7.216625 4.4478 0 20 20 0.3883082 -0.3977414 0.0458990
x1 2 10000 14.9664 7.384858 14.0 14.643500 7.4130 0 39 39 0.3800873 -0.4494918 0.0738486
x2 3 10000 29.8458 13.730130 28.0 29.279875 14.8260 0 73 73 0.3560139 -0.5703444 0.1373013
gender 4 10000 0.5000 0.500025 0.5 0.500000 0.7413 0 1 1 0.0000000 -2.0002000 0.0050003

Contrasts

The left part of the table is with gender as treatment contrast (0 vs. 1) and the right part with gender as effect contrast (-1 vs. 1)

# Gender has values 0 vs. 1 (treatment contrast)
fit1 <- lm(y ~ gender * x1 * x2, data = dat)

# Gender hast -1 vs. 1 (effect contrast)
dat$gender <- car::recode(dat$gender, "0 = -1; 1 = 1")

fit2 <- lm(y ~ gender * x1 * x2, data = dat)

sjPlot::tab_model(fit1, fit2, show.std = TRUE, show.ci = FALSE, col.order = c("est", "se", "std.est", "p"), digits = 4)
  y y
Predictors Estimates std. Beta p Estimates std. Beta p
(Intercept) -1.7305 0.0063 <0.001 -2.4594 0.0063 <0.001
gender -1.4577 -0.1888 <0.001 -0.7288 -0.1888 <0.001
x1 0.0024 -0.0019 0.913 -0.0027 -0.0019 0.848
x2 0.3366 0.9998 <0.001 0.3334 0.9998 <0.001
gender × x1 -0.0103 -0.0047 0.720 -0.0051 -0.0047 0.720
gender × x2 -0.0063 -0.0061 0.679 -0.0031 -0.0061 0.679
x1 × x2 -0.0000 0.0011 0.979 0.0001 0.0011 0.909
(gender × x1) × x2 0.0001 0.0016 0.872 0.0001 0.0016 0.872
Observations 10000 10000
R2 / R2 adjusted 0.759 / 0.759 0.759 / 0.759
 
Copyright 2023, Jürgen Wilbert